import { createI18n } from 'vue-i18n'   // 与vue2的VueI18n使用方式不同
import zh from '@/locales/zh.json'
import en from '@/locales/en.json'
import LS from '@/plugins/localstorage'
 
const LANGUAGE = ['en', 'zh']

function getLang() {
  const lang = LS.get('lang')
  if (lang && LANGUAGE.indexOf(lang) != -1) {
    return lang
  }
  return 'en'
}

const i18n = createI18n({
  legacy: false,
  locale: getLang(),
  fallbackLocale: 'zh',
  globalInjection: true,
  messages: {
    zh,
    en,
  }
})
 
export default i18n
